<include file="Public:pageHeader"/>
<link rel=" stylesheet" type="text/css" href="_STATIC_/css/member.css?v=<?php echo time(); ?>" />
<!--主区域-->
<div class="mainBox on">
    <div class="my-page">
        <div class="wrapper"">
        <div class="my_p">
            <include file="Member:memberLeft"/>
            <div class="my_form">
                <p class="m_p1">当前位置：商标上传</p>
                <div class="line"></div>
                <div id="trademarksUploadBox">
                    <form method="post" id="uploadForm">
                        <input type="file" name="file" id="file">
                        <input type="button" id="uploadFile" value="立即上传">
                    </form>
                    <div class="uploadFileNote" style="margin-top: 30px">注：请严格按照文件模板进行文件上传！<a href="_STATIC_/system_template/商标上传模板.zip?v=<?php echo date("YmdHi"); ?>">下载模板文件</a></div>
                    <div class="uploadFileNote" id="uploadView" style="margin-top: 30px; display: none">
                        最新处理:<span id="totalCount">0</span>个商标；
                        处理状态：<span id="handleStatus">……</span>；
                        已处理:<span id="processedCount">0</span>个商标；
                        成功:<span id="sucCount">0</span>个商标；
                        失败:<span id="failCount">0</span>个商标
                    </div>
                    <div class="uploadFileNote" id="failExportUrl" style="margin-top: 30px; display: none">
                        <a href="/member/exportFailTrademarkResult.html" style="cursor: pointer">导出失败商标</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<!--底部区域-->
<include file="Public:pageFooter" />
</body>
</html>
<script type="text/javascript">
var uploadsn = "{$member['id']}";
var randnumber = "{$randnumber}";
setInterval("getUploadResult()",2000);
$('#uploadFile').click(function(){
    var fileEle = document.getElementById('file');
    var fileObj = null;
    if(fileEle.files){
        fileObj = fileEle.files[0];
        if( fileObj == null || fileObj == 'undefined' ){
            return errmsg("请选择上传文件！");
        }
        let index = fileObj.name.lastIndexOf('.');
        let fileName = fileObj.name.substring(0, index);
        let fileType = fileObj.name.substring(index + 1, fileObj.name.length);  //index是点的位置。点的位置加1再到结尾
        if( fileType != 'csv' ){
            return errmsg("文件类型不正确！");
        }
        /*
        if( fileObj.type.search("excel") == -1 ){
            return errmsg("文件非excel类型！");
        }
         */
        let fileSize = fileObj.size;
        if( fileSize > 1024 * 1024 * 5 ){
            return errmsg("文件大小不能超过5M！");
        }
        box_waite("请耐心等待……");
        var formData = new FormData();
        formData.append('file', fileObj);
        var xml = ajaxFunction();
        xml.open("post", '/member/trademarksuploadFile/randnumber/'+randnumber+'.html', true);
        xml.send(formData);
        xml.onreadystatechange = function () {
            box_close();
            if (xml.readyState == 4 && xml.status == 200) {
                var data = $.parseJSON(xml.responseText);
                if( data.status == 0 ){
                    return errmsg(data.msg);
                }else{
                    return false;
                }
            }
        }
        return false;
    }else{
        return errmsg("浏览器不兼容，请使用高版本浏览器！")
    }
    return false;
});

/**
 * 获取程序执行结果
 */
function getUploadResult(){
    $.ajax({
        url:"/member/getTrademarksuploadResult.html",
        data: {},
        cache: false,
        async: false,
        type: "POST",
        dataType: 'json',
        success: function(res){
            if( res.status == 0 ){
                return errmsg(res.msg);
            }else{
                var data = res.data;
                var handleStatus = data.handleStatus;
                var sucCount = data.sucCount;
                var failCount = data.failCount;
                var totalCount = data.totalCount;
                var processedCount = data.processedCount;
                $("#sucCount").html(sucCount);
                $("#failCount").html(failCount);
                $("#totalCount").html(totalCount);
                $("#processedCount").html(processedCount);
                if( handleStatus >= 0 ){
                    if( handleStatus == 0 ){
                        $("#handleStatus").html("等待处理");
                    }
                    if( handleStatus == 1 ){
                        $("#handleStatus").html("处理中");
                    }
                    if( handleStatus == 2 ){
                        $("#handleStatus").html("处理完成");
                    }
                    if( failCount > 0 ){
                        $("#failExportUrl").show();
                    }
                    $("#uploadView").show();
                }
                return false;
            }
        }
    })
}

</script>